package com.jzt.qf.service.impl;

import com.alibaba.fastjson.JSON;
import com.jzt.qf.beans.HttpResult;
import com.jzt.qf.beans.UploadBase;
import com.jzt.qf.beans.jztBean.OutStockPlan_Upload;
import com.jzt.qf.beans.qfBean.ZxyUploadbillJzt;
import com.jzt.qf.dao.BuyBackBillDao;
import com.jzt.qf.dao.SaleBillDao;
import com.jzt.qf.dao.UploadbillJztDao;
import com.jzt.qf.https.JztApi;
import com.jzt.qf.service.BuyBackBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 　* @description:采购退回单service实现类
 * 　* @author zxy
 * 　* @date 2020-07-23 14:58
 */
@Service
@Slf4j
public class BuyBackBillServiceImpl implements BuyBackBillService {
    @Resource
    private BuyBackBillDao buyBackBillDao;
    @Resource
    private UploadbillJztDao uploadbillJztDao;
    @Resource
    private JztApi jztApi;
    @Resource
    private SaleBillDao saleBillDao;

    @Override
    public HttpResult uploadBuyBackBill(String billCode) {
        log.info("采购退回单BuyBackBillServiceImpl访问成功");
        List<OutStockPlan_Upload> outStockPlan_uploads = buyBackBillDao.getBuyBackBill_Upload(billCode);
        log.info("采购退回上传json串" + JSON.toJSONString(outStockPlan_uploads));
        HttpResult httpResult = jztApi.HttpRequest(
                new UploadBase("gt", "saveData", outStockPlan_uploads));
        log.info("上传采购退回单返回数据" + JSON.toJSONString(httpResult));
        //TODO 修改中间库数据
        if (httpResult.isFlag()) {
            for (OutStockPlan_Upload outStockPlan_upload : outStockPlan_uploads) {
                ZxyUploadbillJzt zxyUploadbillJzt = new ZxyUploadbillJzt();
                zxyUploadbillJzt.setBillcode(outStockPlan_upload.getBiz_Bill_No());
                zxyUploadbillJzt.setOrd(Integer.parseInt(outStockPlan_upload.getBill_Dtl_Id()));
                zxyUploadbillJzt.setBilltype(6);
                uploadbillJztDao.updateFlags(zxyUploadbillJzt);
            }
            int i = saleBillDao.updateGspOutBillOutQty0(billCode);
        }
        return httpResult;
    }
}
